package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.security.annotation.InnerAuth;

import com.ruoyi.system.api.domain.SysMenu;
import com.ruoyi.system.service.ISysMenuService;

import static com.ruoyi.common.security.utils.SecurityUtils.getUserId;

/**
 * 菜单权限内部Controller，实现远程feign接口com.ruoyi.system.api.RemoteSysMenuService。
 * 
 * @author ruoyi
 * @date 2023-04-27
 */
@RestController
@RequestMapping("/inner/menu")
public class SysMenuInnerController
{
    @Autowired
    private ISysMenuService sysMenuService;

    /**
     * 查询菜单权限列表
     */
    @InnerAuth
    @PostMapping("/list")
    public R<List<SysMenu>> selectSysMenuList(SysMenu sysMenu)
    {
        List<SysMenu> list = sysMenuService.selectMenuList(sysMenu, getUserId());
        return R.ok(list);
    }

    /**
     * 获取菜单权限详细信息
     */
    @InnerAuth
    @GetMapping(value = "/{menuId}")
    public R<SysMenu> selectSysMenuByMenuId(@PathVariable("menuId") Long menuId)
    {
        SysMenu sysMenu = sysMenuService.selectMenuById(menuId);
        return R.ok(sysMenu);
    }

    /**
     * 新增菜单权限
     */
    @InnerAuth
    @PostMapping
    public R<Integer> insertSysMenu(@RequestBody SysMenu sysMenu)
    {
        Integer result = sysMenuService.insertMenu(sysMenu);
        return R.ok(result);
    }

    /**
     * 修改菜单权限
     */
    @InnerAuth
    @PutMapping
    public R<Integer> updateSysMenu(@RequestBody SysMenu sysMenu)
    {
        Integer result = sysMenuService.updateMenu(sysMenu);
        return R.ok(result);
    }

    /**
     * 删除菜单权限
     */
	@InnerAuth
	@DeleteMapping("/{menuIds}")
    public R<Integer> deleteSysMenuByMenuIds(@PathVariable Long menuIds)
    {
        Integer result = sysMenuService.deleteMenuById(menuIds);
        return R.ok(result);
    }

}
